package com.faintlight.repository;

import com.faintlight.model.Capsule;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface CapsuleRepository extends JpaRepository<Capsule, Long> {
    List<Capsule> findByCreatedBy_IdAndStatus(Long userId, Capsule.Status status);
    @Query("SELECT c FROM Capsule c WHERE c.unlockTime <= :now AND c.status = com.faintlight.model.Capsule$Status.LOCKED")
    List<Capsule> findLockCapsulesBefore(LocalDateTime now);
    long countByCreatedBy_Id(Long userId);
    List<Capsule> findByCreatedBy_Id(Long userId);
    @Query("SELECT c FROM Capsule c WHERE c.createdBy.id = :userId ORDER BY c.createdAt DESC")
    List<Capsule> findByCreatedBy_IdOrderByCreatedAtDesc(Long userId);
}